//
//  ShellProfitHeadView.m
//  ShellWallert
//
//  Created by lvzhao on 2019/10/24.
//  Copyright © 2019 VV. All rights reserved.
//

#import "ShellProfitHeadView.h"
#import "ShellProfitViewModel.h"

@interface  ShellProfitHeadView()

@property (nonatomic,strong) ShellProfitViewModel *viewModel;

//全网数据
@property (nonatomic,strong) NSMutableArray *detailLabArray;

@end
@implementation ShellProfitHeadView

- (instancetype)initViewModel:(ShellProfitViewModel *)viewModel
{
    self = [super init];
    if (self) {
        
        self.viewModel = (ShellProfitViewModel *)viewModel;
        [self setupView];
    }
    return self;
}

#pragma mark - setupView
- (void)setupView{
    
    ///!!!:今日收益
    UILabel *todayLab = [UILabel lz_labelWithText:LZLocalizedString(@"今日收益") fontSize:k_textBoldFont(16) color:UIColorHex(0xFFFFFF)];
    [self addSubview:todayLab];
    [todayLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(20);
        make.left.mas_equalTo(15);
        make.width.mas_equalTo(200);
        make.height.mas_equalTo(22);
    }];
    
    UIView *contetnView = [[UIView alloc] init];
    contetnView.backgroundColor = UIColorHex(0x08233F);
    contetnView.cornerRadius = 8;
    [self addSubview:contetnView];
    [contetnView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(todayLab.mas_bottom).mas_offset(10);
        make.left.mas_equalTo(15);
        make.width.mas_equalTo(K_SCREENWIDTH - 30);
        make.height.mas_equalTo(150);
    }];
    
    
    NSArray *details = @[LZLocalizedString(@"订单数量"),@"0",
                        LZLocalizedString(@"订单金额"),@"0 USDT",
                        LZLocalizedString(@"订单收益"),@"0 USDT",
                         LZLocalizedString(@"矿池总奖励"),@"0 USDT",];
       
    //每个Item宽高
    CGFloat H = 20;
    CGFloat W = (K_SCREENWIDTH - 30 - 34 - 10)/2.0;
    //每行列数
    NSInteger rank = 2;
    //每列间距
    CGFloat rankMargin = 10;
    //每行间距
    CGFloat rowMargin = 6;
    //Item索引 ->根据需求改变索引
    NSUInteger index = details.count;
    //Item top
    CGFloat top = 23;
       
    for (int i = 0 ; i< index; i++) {
       UILabel *detailLab = [UILabel lz_labelWithText:details[i] fontSize:k_textFont(14) color:UIColorHex(0x8D99B2)];
       detailLab.adjustsFontSizeToFitWidth = YES;
       //Item X轴
       CGFloat X = (i % rank) * (W + rankMargin) + 20;
       //Item Y轴
       NSUInteger Y = (i / rank) * (H +rowMargin);
       if(i%2 == 0){
           detailLab.textColor = UIColorHex(0x8D99B2);
           W = 150;
           
       } else {
           [detailLab lz_rightAlignment];
           detailLab.textColor = UIColorHex(0xFFFFFF);
            W = K_SCREENWIDTH - 150 - 30 - 10 - 30;
           [self.detailLabArray addObject:detailLab];
       }

       detailLab.frame = CGRectMake(X, Y + top, W, H);
       [contetnView addSubview:detailLab];

    }
    ///!!!:历史收益
    UILabel *historyLab = [UILabel lz_labelWithText:LZLocalizedString(@"历史收益") fontSize:k_textBoldFont(16) color:UIColorHex(0xFFFFFF)];
    [self addSubview:historyLab];
    [historyLab mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.mas_equalTo(contetnView.mas_bottom).mas_offset(20);
       make.left.mas_equalTo(15);
       make.width.mas_equalTo(200);
       make.height.mas_equalTo(22);
    }];

    
    
    [self.viewModel.reloadSubject subscribeNext:^(id  _Nullable x) {
        if ([x integerValue] == 6) {
            NSString *orderCount = [NSString stringWithFormat:@"%ld",(long)self.viewModel.profitModel.orderCount];
            NSString *orderAmount = [NSString stringWithFormat:@"%f",self.viewModel.profitModel.orderAmount].saveDecimal;
            NSString *orderProfit = [NSString stringWithFormat:@"%f",self.viewModel.profitModel.orderProfit].saveDecimal;
            NSString *hashRateAward = [NSString stringWithFormat:@"%f",self.viewModel.profitModel.hashRateAward].saveDecimal;

            
            NSArray *details = @[orderCount,
                                 [NSString stringWithFormat:@"%@ USDT",orderAmount],
                                 [NSString stringWithFormat:@"%@ USDT",orderProfit],
                                 [NSString stringWithFormat:@"%@ USDT",hashRateAward]];
            for (int i = 0; i < self.detailLabArray.count; i++) {
                UILabel *detailLab = self.detailLabArray[i];
                detailLab.text = details[i];
            }
        }
    }];
    
    
    
}


- (NSMutableArray *)detailLabArray{
    if (!_detailLabArray) {
        _detailLabArray = [[NSMutableArray alloc] init];
    }
    return _detailLabArray;
}

@end
